package jp.sourceforge.akjrcp.ui.param;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;

public class ParamTab extends AbstractParamItem{
	
	private Map<String,TabItem> tabItems=new HashMap<String,TabItem>();
	private Map<String,Composite> composites=new HashMap<String,Composite>();
	private TabFolder tabFolder;
	private String key;
	private String value;
	public ParamTab(Composite parent,int style,String key){
		super();
		tabFolder=new TabFolder(parent,style);
		this.key=key;
		tabFolder.addSelectionListener(new SelectionCheck());
	}
	public Composite createGridLayoutTab(String label,int style){
		TabItem item=new TabItem(tabFolder,style);
		item.setText(label);
		Composite composite=new Composite(tabFolder,SWT.NULL);
		composite.setLayout(new GridLayout());
		item.setControl(composite);
		
		if(tabItems.size()==0){
			value=label;
			}
		
		tabItems.put(label,item);
		composites.put(label,composite);
		
		
		return composite;
	}
	
	public String getValue(){
		int index=tabFolder.getSelectionIndex();
		if(index>=0){
			TabItem item=tabFolder.getItem(index);
			if(item!=null){
				return item.getText();
			}
		}
		return "";
	}
	public String getKey() {
		
		return key;
	}
	
	public boolean isModified() {
		return getValue().equals(value);
	}
	public void setParamItemActionListener(ParamItemActionListener listener) {
		// TODO Auto-generated method stub
		
	}
	public void setValue(String value) {
		this.value=value;
		
		for(int i=0;i<tabFolder.getItemCount();i++){
			TabItem item=tabFolder.getItem(i);
			if(item.getText().equals(value)){
				tabFolder.setSelection(i);
				break;
			}
		}
	}
	
	
	
}
